package org.zsqx.action;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.zsqx.bean.Disaster;
import org.zsqx.bean.DisasterDefaultSet;
import org.zsqx.bean.DisasterUpload;
import org.zsqx.bean.Dstype;
import org.zsqx.bean.Linkman;
import org.zsqx.bean.Qfr;
import org.zsqx.bean.Town;
import org.zsqx.bean.UsrReport;
import org.zsqx.tools.DisTools;
import org.zsqx.tools.ExcelTools;
import org.zsqx.tools.FileBean;
import org.zsqx.tools.FileTools;
import org.zsqx.tools.FreemarkTools;
import org.zsqx.tools.LotusTools;
import org.zsqx.tools.PropertiesTools;
import org.zsqx.tools.UploadTools;

import cDao.CdaoTools;
import cDao.annotation.OrderByEnum;
import freemarker.template.TemplateException;

@Action(value="/disasterAction",results={
		@Result(name="report",location="disasterAction!reportAll.action",type="redirect",params={"message","${message}"}),
		@Result(name="disasterPage",location="/login/disasterDetail.jsp"),
		@Result(name="disasterList",location="/login/disasterList.jsp"),
		@Result(name="disasterUploadPage",location="/login/disasterUploadDetail.jsp"),
		@Result(name="disListRedirect",location="/disasterAction!disUplodaList.action",type="redirect",params={"message","${message}"}),
		@Result(name="disasterUploadList",location="/login/disasterUploadList.jsp"),
		@Result(name="uploadHistory",location="/login/disasterUploadHistory.jsp"),
		@Result(name="disasterDefaultSetPage",location="/login/system/disasterDefault.jsp"),
		@Result(name="outputExcel",type="stream",params={"contentType","application/vnd.ms-excel","bufferSize","2046","inputName","excelStream","contentDisposition","attachment;filename=${fileNames}"}),
		@Result(name="input",location="/error.jsp")
		
})
public class DisasterAction extends BaseAction {
	private List<UsrReport> reportList;
	private List<Linkman> linkmans;
	private List<Qfr> qfrs;
	private List<Dstype> dstypes;
	private List<Town> towns;
	private String actionName;
	private Disaster disaster;
	private List<Disaster> disasterList;
	private DisasterUpload disasterUpload;
	private List<DisasterUpload> disasterUploadList;
	private Integer[] disasterIds;
	private InputStream excelStream;
	private String fileNames;
	private String startTime;
	private String endTime;
	private File upload;
    private String uploadFileName;
    private String uploadContentType;
    private List<FileBean> fileList;
    
    private DisasterDefaultSet disasterDefaultSet;
	//添加灾情记录
    public String disPage(){
		String ids=request.getParameter("ids");
		String allImages="";
		if (null!=ids&&!"()".equals(ids)) {
			reportList=new ArrayList<UsrReport>();
			String[] arr=ids.split(",");
			for (int i =0;i<arr.length;i++) {
				UsrReport usrReport=new UsrReport();
				usrReport.setReNum(Integer.parseInt(arr[i]));
				usrReport=(UsrReport) rd.findById(usrReport);
				if(i==arr.length-1){
					if(null!=usrReport.getReImage()&&""!=usrReport.getReImage())
					allImages+="../meteorology_wap\\images\\upload/"+usrReport.getReImage();
				}else{
					if(null!=usrReport.getReImage()&&""!=usrReport.getReImage())
					allImages+="../meteorology_wap\\images\\upload/"+usrReport.getReImage()+",";
				}
				System.out.println("灾情审核合并图片:"+allImages);
				reportList.add(usrReport);
			}
		}
		if(null!=disaster){
			disaster = (Disaster) rd.findById(disaster);
		}else{
			PropertiesTools pt = new PropertiesTools();
			disasterDefaultSet = (DisasterDefaultSet) pt.getPropertyesBean(new DisasterDefaultSet());
			disaster = new Disaster();
			disaster.setStationid(disasterDefaultSet.getStationid());
			disaster.setStationname(disasterDefaultSet.getStationname());
			disaster.setProvince(disasterDefaultSet.getProvince());
			disaster.setCity(disasterDefaultSet.getCity());
			disaster.setTelephone(disasterDefaultSet.getTelephone());
			disaster.setPlongitude(disasterDefaultSet.getLongitude());
			disaster.setPlatitude(disasterDefaultSet.getLatitude());
			if(null!=allImages&&""!=allImages)
			disaster.setPic(allImages);
		}
		linkmans = rd.find(new Linkman());
		qfrs = rd.find(new Qfr());
		dstypes = rd.find(new Dstype());
		towns = rd.find(new Town());
		return "disasterPage";
	}
	public String saveDis(){
		int id = rd.save(disaster);
		if(id == 0){
			message = "操作失败!";
		}else{
			message = "操作成功!";
		}
		return "report";
	}
	public String updateDis(){
		int id = rd.update(disaster);
		if(id == 0){
			message = "操作失败!";
		}else{
			message = "操作成功!";
		}
		return "report";
	}
	/*上报历史*/
	public String uploadHistory(){
		long timeFrom;
		long timeTo;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			if (null==startTime) {
				timeFrom=0;
			}else{
				timeFrom=sdf.parse(startTime).getTime();
			}
			if(null==endTime){
				timeTo=new Date().getTime();
			}else{
				timeTo=sdf.parse(endTime).getTime();
			}
			//G://apache-tomcat-6.0.29//webapps//zsqx_google
			String url=servletContext.getRealPath("login/flt/xmlTemplete");
			fileList=FileTools.getFiles(url,timeFrom,timeTo);
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "uploadHistory";
	}
	private void sendXML(){
		String xmlName = "";
		try {
			String ftlPath = servletContext.getRealPath("login/flt")+"/";
			FreemarkTools tf = new FreemarkTools();
			xmlName = tf.buildXml(ftlPath, disasterUpload);
			message += "成功生成<a href='login/flt/xmlTemplete/"+xmlName+"' target='_blank'>"+xmlName+"</a>文件";
			LotusTools lt = new LotusTools();
			String str=new SimpleDateFormat("yyyy年MM月dd日").format(new Date());
			if(lt.sendMail(str+"中山市"+disasterUpload.getDistypename()+"灾情上报", ftlPath+"xmlTemplete/"+xmlName,disasterUpload.getInfosources())){//disasterUpload.getDistypename()灾害类型
				message += "<br/>lotus邮件发送成功！";
			}else{
				message += "<br/>lotus邮件发送失败！";
			}
		} catch (IOException e) {
			message += "生成"+xmlName+"文件出错！";
			e.printStackTrace();
		} catch (TemplateException e) {
			message += "生成"+xmlName+"文件出错！";
		}
	}
	public String reportAll() throws UnsupportedEncodingException{
		if(null == disaster){
			disaster = new Disaster();
		}
		
		pageBean = rd.getPageBean(currentPage, rd.getCount(disaster), pageSize);
		rd.setPageBean(pageBean).setStartTime(startTime).setEndTime(endTime).setFieldTime("starttime").setOrderByField("starttime");
		rd.setOrderBy(OrderByEnum.DESC);
		disasterList = rd.findByPage(disaster);
		if(null != message){
			message = new String(message.getBytes("iso-8859-1"),"utf-8");
		}
		rd.setFieldTime(null);
		rd.setOrderBy(null);
		dstypes = rd.find(new Dstype());
		towns = rd.find(new Town());
		return "disasterList";
	}
	public String disDelete(){
		int de = rd.delete(disaster);
		if(de!=0){
			message = SUCCESS;
		}else{
			message = FAIL;
		}
		return "report";
	}
	//灾情合并
	public String disSum(){
		PropertiesTools pt = new PropertiesTools();
		disasterDefaultSet = (DisasterDefaultSet) pt.getPropertyesBean(new DisasterDefaultSet());
		//disasterUpload = new DisasterUpload();
		
		DisTools dt = new DisTools();
		actionName = "disUploadSave";
		disasterUpload = dt.changeDis(disasterIds);
		disasterUpload.setStationid(disasterDefaultSet.getStationid());
		disasterUpload.setPlongitude(disasterDefaultSet.getLongitude());
		disasterUpload.setPlatitude(disasterDefaultSet.getLatitude());
		linkmans = rd.find(new Linkman());
		qfrs = rd.find(new Qfr());
		dstypes = rd.find(new Dstype());
		towns = rd.find(new Town());
		return "disasterUploadPage";
	}
	//灾情上报列表 -添加上报
	public String disUploadPage(){
		if(disasterUpload!=null){
			disasterUpload = (DisasterUpload) rd.findById(disasterUpload);
		}else{
			PropertiesTools pt = new PropertiesTools();
			disasterDefaultSet = (DisasterDefaultSet) pt.getPropertyesBean(new DisasterDefaultSet());
			disasterUpload = new DisasterUpload();
			disasterUpload.setStationid(disasterDefaultSet.getStationid());
			disasterUpload.setStationname(disasterDefaultSet.getStationname());
			disasterUpload.setProvince(disasterDefaultSet.getProvince());
			disasterUpload.setCity(disasterDefaultSet.getCity());
			disasterUpload.setTelephone(disasterDefaultSet.getTelephone());
			disasterUpload.setPlongitude(disasterDefaultSet.getLongitude());
			disasterUpload.setPlatitude(disasterDefaultSet.getLatitude());
		}
		linkmans = rd.find(new Linkman());
		qfrs = rd.find(new Qfr());
		dstypes = rd.find(new Dstype());
		towns = rd.find(new Town());
		return "disasterUploadPage";
	}
	//发送灾情上报
	public String disUploadSave(){
		disasterUpload.setInfosources(disasterUpload.getInfosources().replaceAll(", ",""));
		FreemarkTools tf = new FreemarkTools();
		//System.out.println("**"+tf.getDate());
		disasterUpload.setSendtime(tf.getDate());
		int id = rd.save(disasterUpload);
		System.out.println(disasterUpload.getInfosources());
		if(id == 0){
			message = "操作失败!";
		}else{
			message = "操作成功!";
			sendXML();
		}
		return "disListRedirect";
	}
	public String disUploadUpdate(){
		int id = rd.update(disasterUpload);
		System.out.println(disasterUpload.getPic());
		if(id == 0){
			message = "操作失败!";
		}else{
			message = "操作成功!";
			sendXML();
		}
		return "disListRedirect";
	}
	public String disUploadDelete(){
		int id = rd.delete(disasterUpload);
		if(id == 0){
			message = "操作失败!";
		}else{
			message = "操作成功!";
		}
		return "disListRedirect";
	}
	public String disUplodaList() throws UnsupportedEncodingException{
		if(null != message){
			message = new String(message.getBytes("iso-8859-1"),"utf-8");
		}
		if(disasterUpload==null)disasterUpload = new DisasterUpload();
		pageBean = rd.getPageBean(currentPage, rd.getCount(disasterUpload), pageSize);
		rd.setPageBean(pageBean).setOrderBy(OrderByEnum.DESC).setStartTime(startTime).setEndTime(endTime).setFieldTime("starttime");
		disasterUploadList = rd.findByPage(disasterUpload);
		rd.setFieldTime(null);
		dstypes = rd.find(new Dstype());
		towns = rd.find(new Town());
		return "disasterUploadList";
	}
	
	//图片上传
	 public void everyUpload() throws Exception{
    	String root = servletContext.getRealPath("resources/disasterUpload");
    	UploadTools ut = new UploadTools();
    	System.out.println(uploadFileName);
    	String fileName = ut.upload(root, upload, root+uploadFileName);
    	response.getWriter().println("<script>parent.getContext('"+fileName+"');</script>");
    }
	//灾情上报默认值设定
	public String disasterDefaultSettingPage(){
		PropertiesTools pt = new PropertiesTools();
		disasterDefaultSet = (DisasterDefaultSet) pt.getPropertyesBean(new DisasterDefaultSet());
		return "disasterDefaultSetPage";
	}
	public String disasterDefaultSetting(){
		PropertiesTools pt = new PropertiesTools();
		pt.setPropertiesBean(disasterDefaultSet);
		return disasterDefaultSettingPage();
	}
	//导出
	public String outputExcel() throws Exception{
//		String absolute_path=request.getRealPath("/");
//		Map<String, String> map=new HashMap<String, String>();
//		map.put("num", "编号");
//		map.put("change", "");
//		map.put("disateraffect", "灾害影响");
//		map.put("evaluatelevel", "评估等级");
//		map.put("forecastserve", "预报服务");
//		map.put("gsummarize", "天气过程描述");
//		map.put("infosources", "信息来源");
//		map.put("kinescope", "");
//		map.put("placename", "地区代号");
//		map.put("platitude", "纬度");
//		map.put("plongitude", "经度");
//		map.put("province", "省");
//		map.put("sdisasterId", "");
//		map.put("sdisasterpid", "");
//		map.put("sendtime", "发送时间");
//		map.put("stationid", "站号");
//		map.put("stationname", "县");
//		map.put("telephone", "联系电话");
//		map.put("underwriter", "签发人");
//		map.put("roadstop", "道路阻塞");
//		map.put("sickname", "疾病名称");
//		map.put("szzwname", "受灾农作物名称");
//		map.put("yxmcname", "影响牧草名称");
//		map.put("endtime", "结束时间");
//		map.put("pic", "图片地址");
//		map.put("starttime", "开始时间");
//		map.put("video", "视频地址");
//		map.put("bcbreakstatus", "损坏桥梁涵洞数量");
//		map.put("czarea", "成灾面积");
//		map.put("deadqt", "死亡人数");
//		map.put("deconomyloss", "电力直接经济损失");
//		map.put("dponddamdestroy", "大型塘坝座数");
//		map.put("dsnumber", "停课学校间数");
//		map.put("siegesqt", "被困人数");
//		map.put("dstoptime", "停电中断时间");
//		map.put("economyloss", "经济总损失");
//		map.put("fbnumber", "发病人数");
//		map.put("bankburstplace", "防洪堤绝口处");
//		map.put("dxlengyth", "断线长度");
//		map.put("floodcompare", "洪水比较值");
//		map.put("othereconomyloss", "其他经济损失");
//		map.put("floodflux", "相关建和洪水流量");
//		map.put("floodheight", "洪峰水位");
//		map.put("foodstuflose", "损失粮食");
//		map.put("fqvehicledestroy", "交通工具损毁数");
//		map.put("ghmorratime", "汽车火车停运时间");
//		map.put("gpnumber", "倒杆根数");
//		map.put("hitsbydisqt", "受灾总人数");
//		map.put("housecollapse", "倒塌损坏房屋间数");
//		map.put("injuredqt", "受伤人数");
//		map.put("jcsseconomyloss", "基础设施直接经济损失");
//		map.put("jeconomyloss", "交通直接经济损失");
//		map.put("jynumber", "转移安置人数");
//		map.put("leconomyloss", "林业直接经济损失");
//		map.put("meconomyloss", "牧业直接经济损失");
//		map.put("missqt", "失踪人数");
//		map.put("neconomyloss", "农业直接经济损失");
//		map.put("planedelaynumber", "飞机航班延误次数");
//		map.put("potwaterdiff", "造成饮水困难人数");
//		map.put("sblose", "设备损失");
//		map.put("seconomyloss", "商业直接经济损失");
//		map.put("shopstop", "停业商店数");
//		map.put("sinkboatnumber", "翻船只数");
//		map.put("sinkboatnumbrt", "运输翻船只数");
//		map.put("sinkboatweight", "翻船中吨位");
//		map.put("sleconomyloss", "干旱直接经济损失");
//		map.put("sllosenumber", "树林损失数");
//		map.put("ssarea", "绝收面积");
//		map.put("sslnumber", "牲畜损失头数");
//		map.put("szarea", "受灾面积");
//		map.put("szmcarea", "受灾牧草面积");
//		map.put("taxeconomyloss", "通讯直接经济损失");
//		map.put("tgbreaklengh", "铁路公路损毁长度");
//		map.put("tgnumber", "停产工厂数");
//		map.put("txtime", "通讯中断时间");
//		map.put("watercompare", "洪峰水位比较值");
//		map.put("xponddamdestroy", "小型塘坝座数");
//		map.put("yeconomyloss", "渔业直接经济损失");
//		map.put("zponddamdestroy", "中型塘坝座数");
//		map.put("place", "发生地");
//		map.put("cpotwaterdiff", "干旱影响");
//		map.put("otherdestroy", "其他影响");
//		map.put("city", "市");
//		map.put("disastertype", "灾害类型");
//		map.put("pnumber", "");
//		map.put("reporter", "报告人");
//		map.put("town", "镇区");
//		map.put("distypename", "灾害类型名称");
//		rd.setOrderBy(OrderByEnum.DESC).setStartTime(startTime).setEndTime(endTime).setFieldTime("starttime");
//		disasterUploadList = rd.find(new DisasterUpload());
//		if (disasterUploadList.size()>0) {
//			String down_path=ExcelTools.writeToExcel("灾情上报", absolute_path,disasterUploadList, map);
//			BufferedInputStream bis = null;
//			BufferedOutputStream bos = null;
//			OutputStream fos = null;
//			InputStream fis = null;
//			File uploadFile = new File(down_path);
//			try {
//				fis = new FileInputStream(uploadFile);
//				bis = new BufferedInputStream(fis);
//				fos = response.getOutputStream();
//				bos = new BufferedOutputStream(fos);
//				String fileName=down_path.substring(down_path.lastIndexOf("\\")+1,down_path.length());
//				//System.out.println(fileName);
//				response.setHeader("Content-disposition", "attachment;filename="+ URLEncoder.encode(fileName, "utf-8"));
//				int bytesRead = 0;
//				byte[] buffer = new byte[8192];
//				while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
//					bos.write(buffer, 0, bytesRead);
//				}
//				bos.flush();
//				fis.close();
//				bis.close();
//				fos.close();
//				bos.close();
//			} catch (FileNotFoundException e) {
//				e.printStackTrace();
//			} catch (UnsupportedEncodingException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		}
		return "outputExcel";
	}
	
	public Disaster getDisaster() {
		return disaster;
	}

	public void setDisaster(Disaster disaster) {
		this.disaster = disaster;
	}

	public List<Disaster> getDisasterList() {
		return disasterList;
	}

	public void setDisasterList(List<Disaster> disasterList) {
		this.disasterList = disasterList;
	}
	public List<UsrReport> getReportList() {
		return reportList;
	}
	public void setReportList(List<UsrReport> reportList) {
		this.reportList = reportList;
	}
	public List<Linkman> getLinkmans() {
		return linkmans;
	}
	public void setLinkmans(List<Linkman> linkmans) {
		this.linkmans = linkmans;
	}
	public List<Qfr> getQfrs() {
		return qfrs;
	}
	public void setQfrs(List<Qfr> qfrs) {
		this.qfrs = qfrs;
	}
	public List<Town> getTowns() {
		return towns;
	}
	public void setTowns(List<Town> towns) {
		this.towns = towns;
	}
	public List<Dstype> getDstypes() {
		return dstypes;
	}
	public void setDstypes(List<Dstype> dstypes) {
		this.dstypes = dstypes;
	}
	public String getActionName() {
		return actionName;
	}
	public void setActionName(String actionName) {
		this.actionName = actionName;
	}
	public Integer[] getDisasterIds() {
		return disasterIds;
	}
	public void setDisasterIds(Integer[] disasterIds) {
		this.disasterIds = disasterIds;
	}
	public DisasterUpload getDisasterUpload() {
		return disasterUpload;
	}
	public void setDisasterUpload(DisasterUpload disasterUpload) {
		this.disasterUpload = disasterUpload;
	}
	public List<DisasterUpload> getDisasterUploadList() {
		return disasterUploadList;
	}
	public void setDisasterUploadList(List<DisasterUpload> disasterUploadList) {
		this.disasterUploadList = disasterUploadList;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public String getUploadContentType() {
		return uploadContentType;
	}
	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}
	public DisasterDefaultSet getDisasterDefaultSet() {
		return disasterDefaultSet;
	}
	public void setDisasterDefaultSet(DisasterDefaultSet disasterDefaultSet) {
		this.disasterDefaultSet = disasterDefaultSet;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	
	public List<FileBean> getFileList() {
		return fileList;
	}
	public void setFileList(List<FileBean> fileList) {
		this.fileList = fileList;
	}
	public InputStream getExcelStream() {
		String absolute_path=request.getRealPath("/");
		Map<String, String> map=new HashMap<String, String>();
		map.put("num", "编号");
		map.put("change", "");
		map.put("disateraffect", "灾害影响");
		map.put("evaluatelevel", "评估等级");
		map.put("forecastserve", "预报服务");
		map.put("gsummarize", "天气过程描述");
		map.put("infosources", "信息来源");
		map.put("kinescope", "");
		map.put("placename", "地区代号");
		map.put("platitude", "纬度");
		map.put("plongitude", "经度");
		map.put("province", "省");
		map.put("sdisasterId", "");
		map.put("sdisasterpid", "");
		map.put("sendtime", "发送时间");
		map.put("stationid", "站号");
		map.put("stationname", "县");
		map.put("telephone", "联系电话");
		map.put("underwriter", "签发人");
		map.put("roadstop", "道路阻塞");
		map.put("sickname", "疾病名称");
		map.put("szzwname", "受灾农作物名称");
		map.put("yxmcname", "影响牧草名称");
		map.put("endtime", "结束时间");
		map.put("pic", "图片地址");
		map.put("starttime", "开始时间");
		map.put("video", "视频地址");
		map.put("bcbreakstatus", "损坏桥梁涵洞数量");
		map.put("czarea", "成灾面积");
		map.put("deadqt", "死亡人数");
		map.put("deconomyloss", "电力直接经济损失");
		map.put("dponddamdestroy", "大型塘坝座数");
		map.put("dsnumber", "停课学校间数");
		map.put("siegesqt", "被困人数");
		map.put("dstoptime", "停电中断时间");
		map.put("economyloss", "经济总损失");
		map.put("fbnumber", "发病人数");
		map.put("bankburstplace", "防洪堤绝口处");
		map.put("dxlengyth", "断线长度");
		map.put("floodcompare", "洪水比较值");
		map.put("othereconomyloss", "其他经济损失");
		map.put("floodflux", "相关建和洪水流量");
		map.put("floodheight", "洪峰水位");
		map.put("foodstuflose", "损失粮食");
		map.put("fqvehicledestroy", "交通工具损毁数");
		map.put("ghmorratime", "汽车火车停运时间");
		map.put("gpnumber", "倒杆根数");
		map.put("hitsbydisqt", "受灾总人数");
		map.put("housecollapse", "倒塌损坏房屋间数");
		map.put("injuredqt", "受伤人数");
		map.put("jcsseconomyloss", "基础设施直接经济损失");
		map.put("jeconomyloss", "交通直接经济损失");
		map.put("jynumber", "转移安置人数");
		map.put("leconomyloss", "林业直接经济损失");
		map.put("meconomyloss", "牧业直接经济损失");
		map.put("missqt", "失踪人数");
		map.put("neconomyloss", "农业直接经济损失");
		map.put("planedelaynumber", "飞机航班延误次数");
		map.put("potwaterdiff", "造成饮水困难人数");
		map.put("sblose", "设备损失");
		map.put("seconomyloss", "商业直接经济损失");
		map.put("shopstop", "停业商店数");
		map.put("sinkboatnumber", "翻船只数");
		map.put("sinkboatnumbrt", "运输翻船只数");
		map.put("sinkboatweight", "翻船中吨位");
		map.put("sleconomyloss", "干旱直接经济损失");
		map.put("sllosenumber", "树林损失数");
		map.put("ssarea", "绝收面积");
		map.put("sslnumber", "牲畜损失头数");
		map.put("szarea", "受灾面积");
		map.put("szmcarea", "受灾牧草面积");
		map.put("taxeconomyloss", "通讯直接经济损失");
		map.put("tgbreaklengh", "铁路公路损毁长度");
		map.put("tgnumber", "停产工厂数");
		map.put("txtime", "通讯中断时间");
		map.put("watercompare", "洪峰水位比较值");
		map.put("xponddamdestroy", "小型塘坝座数");
		map.put("yeconomyloss", "渔业直接经济损失");
		map.put("zponddamdestroy", "中型塘坝座数");
		map.put("place", "发生地");
		map.put("cpotwaterdiff", "干旱影响");
		map.put("otherdestroy", "其他影响");
		map.put("city", "市");
		map.put("disastertype", "灾害类型");
		map.put("pnumber", "");
		map.put("reporter", "报告人");
		map.put("town", "镇区");
		map.put("distypename", "灾害类型名称");
		rd.setOrderBy(OrderByEnum.DESC).setStartTime(startTime).setEndTime(endTime).setFieldTime("starttime");
		disasterUploadList = rd.find(new DisasterUpload());
		InputStream in=null;
		if (disasterUploadList.size()>0) {
			try {
				fileNames=ExcelTools.writeToExcel("灾情上报", absolute_path,disasterUploadList, map)+".xls";
				String realPath="/login/excel/"+fileNames;
				System.out.println(realPath);
				in=ServletActionContext.getServletContext().getResourceAsStream(realPath);
				if(null==in){
					System.out.println("Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name=\"inputName\"> tag specified for this action.检查action中文件下载路径是否正确.");   
				}
			}catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalStateException e) {
				e.printStackTrace();
			} catch (RowsExceededException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NullPointerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WriteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(null!=in){
					try {
						in.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return in;

	}
	public void setExcelStream(InputStream excelStream) {
		this.excelStream = excelStream;
	}
	public String getFileNames() {
		return fileNames;
	}
	public void setFileNames(String fileNames) {
		this.fileNames = fileNames;
	}
	@Override
	public void validate() {
		CdaoTools ct = new CdaoTools();
		startTime = ct.noword(startTime);
		endTime = ct.noword(endTime);
		ct.nowordBean(disaster);
		ct.nowordBean(disasterUpload);
	}
	
	
}
